/* 首页
 * @Author: wujie 
 * @Date: 2018-06-12 11:05:58 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-07-06 11:22:23
 */
import React, { Component } from 'react'
import components from '@/components/index'
import { connect } from 'react-redux'
import actions from '@/actions/main'
import { Modal } from 'antd';

const { BasicInfo, Card, InterfaceInfo, TodaySend, ChangePassWord } = components

class Main extends Component {

  render() {
    const { data, isPassWordShow } = this.props

    return (
      <div>
        <Card title="基本信息">
          <BasicInfo data={data} />
        </Card>
        <InterfaceInfo 
          data={data}
          isPassWordShow={isPassWordShow}
          // onChangePassWord={this.onChangePassWord}
          onResetPassWord={this.onResetPassWord}
          onInterfaceDoc={this.onInterfaceDoc}
          onConnectUs={this.onConnectUs}  
          onPassWordShow={this.onPassWordShow}
          onPassWordHidden={this.onPassWordHidden}
        />
        <TodaySend data={data} />
        {/* 修改密码不要了，改重置密码 */}
        {/* <ChangePassWord 
          visible={this.props.modalVisible}
          handleOk={this.onModalOk}
          handleCancel={this.onModalOk}
        /> */}
      </div>
    )
  }

  componentDidMount() {
    this.props.getData()
  }

  onChangePassWord = () => {
    this.props.showModalChangPwd()
  }

  onResetPassWord = () => {
    const _this = this
    Modal.confirm({
      title: '提示',
      type: 'warning',
      maskClosable: true,
      content: '确定重置密码',
      onOk() {
        _this.props.resetPassWord()
      }
    })
  }

  onModalOk = () => {
    this.props.hideModalChangPwd()
  }

  onInterfaceDoc = () => {
    window.open(this.props.data.docUrl)
  }

  onPassWordShow = () => {
    this.props.showPassword()
  }
  
  onPassWordHidden = () => {
    this.props.hiddenPassword()
  }

  onConnectUs = () => {
    window.open(`http://shang.qq.com/email/stop/email_stop.html?qq=${this.props.data.QQ}`)
  }

}

const mapStateToProps = ({ mainReducer }) => ({...mainReducer})

export default connect(mapStateToProps, { ...actions })(Main)